define(['jquery', 'bootstrap','backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/worklist/index',
                    add_url: '',
                    edit_url: '',
                    del_url: '',
                    multi_url: '',
                    table: 'page',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url+'?staffid='+table.data('id'),
                columns: [
                    [
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'order.user_name', title: __('Username'),operate: false},
                        {field: 'order.address', title: __('address'),operate: false},
                        {field: 'w_type', title: __('工作类型'),operate: false,formatter: Table.api.formatter.status1},
                        {field: 'order.telphone', title: __('telphone'),operate:false},
                        //启用时间段搜索
                        {field: 'begintime', title: __('begintime'),  operate:false},
                        {field: 'endtime', title: __('endtime'),  operate:false},
                    ]
                ],
                //普通搜索
                commonSearch: false,
                searchFormVisible: true,
                titleForm: '', //为空则不显示标题，不定义默认显示：普通搜索
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            //刷新表单
            $(document).on("click", ".btn-refreshpic", function () {
                table.bootstrapTable('refresh');
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        addworklog: function () {
            Controller.api.bindevent();
        },

        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            formatter: {
                operate: function (value, row, index) {
                    //返回字符串加上Table.api.formatter.operate的结果
                    //默认需要按需显示排序/编辑/删除按钮,则需要在Table.api.formatter.operate将table传入
                    //传入了table以后如果edit_url为空则不显示编辑按钮,如果del_url为空则不显显删除按钮
                    return '<a class="btn btn-info btn-xs btn-detail"><i class="fa fa-user"></i> ' + '工作安排' + '</a> '
                        + Table.api.formatter.operate(value, row, index, $("#table"));
                },
            },
            events: {
                operate: $.extend({
                    'click .btn-detail': function (e, value, row, index) {
                        /* $.ajax({
                              url:"",
                             data:"",
                             dataType:"json",
                             type:"get",
                             success:function () {
                             }
                         });*/
                        var table = $("#table");
                        Backend.api.open('staff/myinterview/addworklog'+'?id='+row['id'], '工作安排');
                    }
                }, Table.api.events.operate)
            }
        }
    };
    return Controller;
});